<?php

require_once(WSB_MODULES_PATH . 'sherpa/forms/SherpaForm.php');

class Sherpa_Form_Registration extends Sherpa_Form_SherpaForm
{

	public function init()
    {
    	$this->setName('registration');

    	// First name
        $element = new Zend_Form_Element_Text('firstname');
        $element->setLabel('registrationFirstname');
        $element->setRequired(true);
        $element->addFilter(new Zend_Filter_StringTrim());
		$this->addElement($element);

    	// Last name
        $element = new Zend_Form_Element_Text('lastname');
        $element->setLabel('registrationLastname');
        $element->setRequired(true);
        $element->addFilter(new Zend_Filter_StringTrim());
		$this->addElement($element);

    	// E-Mail
        $element = new Zend_Form_Element_Text('email');
        $element->setLabel('registrationEmail');
        $element->setRequired(true);
        $emailValidator = new WSB_Validator_EmailAddressSimple();
		$emailValidator->setMessages(array(
			WSB_Validator_EmailAddressSimple::INVALID => 'registrationInvalidEmailAddress'
    	));
        $element->addValidator($emailValidator);
        $uniqueFeuserValidator = new WSB_Validator_UniqueFeuser();
        $uniqueFeuserValidator->setMessages(array(
        	WSB_Validator_UniqueFeuser::USERNAME_EXISTS => 'registrationEmailExists'
       	));
        $element->addValidator($uniqueFeuserValidator);
        $element->addFilter(new Zend_Filter_StringTrim());
		$this->addElement($element);

		$stringLengthValidator = new Zend_Validate_StringLength(5, 50);
        $stringLengthValidator->setMessages(array(
			Zend_Validate_StringLength::TOO_SHORT  => 'registrationStringLengthTooShort',
			Zend_Validate_StringLength::TOO_LONG => 'registrationStringLengthTooLong'
        ));

    	// Password
		$element = new Zend_Form_Element_Password('password');
        $element->setLabel('registrationPassword');
        $element->setRequired(true);
        $element->addValidator($stringLengthValidator);
		$token = isset($_POST['confirmPassword']) ? $_POST['confirmPassword'] : '';
        $identicalValidator = new Zend_Validate_Identical($token);
        $identicalValidator->setMessages(array(
			Zend_Validate_Identical::NOT_SAME => 'registrationPasswordsNotSame',
			Zend_Validate_Identical::MISSING_TOKEN => 'registrationMissingToken'
        ));
        $element->addValidator($identicalValidator);
        $element->addFilter(new Zend_Filter_StringTrim());
		$this->addElement($element);

    	// Confirm password
		$element = new Zend_Form_Element_Password('confirmPassword');
        $element->setLabel('registrationConfirmpassword');
        $element->setRequired(true);
        $element->addValidator($stringLengthValidator);
        $element->addFilter(new Zend_Filter_StringTrim());
		$this->addElement($element);

    	// Button
		$element = new Zend_Form_Element_Image('btnCreateAccount');
	    $element->setAttrib('src', 'sherpa/img/btn-konto-erstellen.gif');
		$this->addElement($element);

    }

}
